<?php

/**
 * 公共函数
 * ============================================================================
 * * 版权所有 2005-2012 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: testyang $
 * $Id: lib_main.php 15013 2008-10-23 09:31:42Z testyang $
*/

//钱箱数据获取 yjmp
function get_cash_drawer()
{
    $cash_drawer = $GLOBALS['db']->getAll('SELECT * FROM '.$GLOBALS['ecs']->table('cash_drawer').' WHERE 1');

    foreach ($cash_drawer as $key => $value) 
    {
        $cash_drawer[$key]['in_come'] = price_format($value['in_come'],false);    
        $cash_drawer[$key]['out_come'] = price_format($value['out_come'],false);    
        $cash_drawer[$key]['balance'] = price_format($value['balance'],false); 
        $cash_drawer[$key]['add_time'] = local_date('Y-m-d H:i', $value['add_time']);  
    }

    return $cash_drawer;
}

//获取on hold order yjmp
function get_on_hold_info()
{
    $on_hold_info = $GLOBALS['db']->getAll('SELECT * FROM '.$GLOBALS['ecs']->table('on_hold_order').' WHERE user_id = '.$_SESSION['user_id'].'');
    $show_data_arr = array();
    $temp_data = array();
    $temp_sn = '';
    $temp_price = 0;
    $pos = -1;
    $add_time = 0;
    foreach ($on_hold_info as $key => $value) 
    {
        if ($add_time == $value['add_time']) {
            $temp_sn .= ' '.$value['goods_sn'];
            $temp_price += $value['goods_price'] * $value['goods_number'];
            $temp_data['note'] = $value['note'];
            $temp_data['goods_sns'] = $temp_sn;
            $temp_data['price'] = $temp_price;
            $temp_data['time'] = date("h:i a",$value['add_time']);
            $temp_data['add_time'] = $value['add_time'];
            $show_data_arr[$pos] = $temp_data;
        }else{
            $temp_data = array();
            $temp_sn = '';
            $temp_price = 0;
            $pos ++;
            $temp_sn .= ' '.$value['goods_sn'];
            $add_time = $value['add_time'];
            $temp_price += $value['goods_price'] * $value['goods_number'];
            $temp_data['goods_sns'] = $temp_sn;
            $temp_data['price'] = $temp_price;
            $temp_data['note'] = $value['note'];
            $temp_data['time'] = date("h:i a",$value['add_time']);
            $temp_data['add_time'] = $value['add_time'];
            $show_data_arr[$pos] = $temp_data;
        }
    }
    return $show_data_arr;
}

//wp加入购物车

//miracle获取该业务员所有的订单
function get_user_orderlist($uid,$page,$pagecount){
	$limits = ($page-1)*$pagecount;
	$limite = $page*$pagecount;
	$sql =" SELECT *,(goods_amount + shipping_fee + insure_fee + pay_fee + pack_fee + card_fee + tax - discount - goods_discount_fee) AS total_fee FROM ".$GLOBALS['ecs']->table('order_info')." WHERE ywid = $uid AND is_webpos = 1 ORDER BY add_time desc limit $limits,$limite";
	//$sql =" SELECT * FROM ".$GLOBALS['ecs']->table('order_info')." WHERE ywid = $uid AND is_webpos = 1 ORDER BY add_time desc limit $pagecount";

	$result = $GLOBALS['db'] ->getAll($sql);
	$order_list = array();
	$i=0;
	foreach($result as $k=>$v){
		$result[$k]['add_date'] = date('Y-m-d H:i:s',$result[$k]['add_time']);
		$result[$k]['province_name'] = get_region_name($v['province']);
		$result[$k]['city_name'] = get_region_name($v['city']);
		$result[$k]['district_name'] = get_region_name($v['district']);
		$result[$k]['total_fee_fomart'] = price_format($v['total_fee'], false);
		if($k>0){
			if(date('Y-m-d',$result[$k]['add_time']) != date('Y-m-d',$result[$k-1]['add_time'])){
				$i++;
			}
		}
		$order_list[$i]['date'] = date('Y-m-d',$result[$k]['add_time']);
		$order_list[$i]['order_list'][] = $result[$k];

	}

	return $order_list;

}

//miracle获取地区名称
function get_region_name($region_id){
	$result='';
	if($region_id>0){
		$sql =" SELECT region_name FROM ".$GLOBALS['ecs']->table('region')." WHERE region_id = $region_id";
		$result = $GLOBALS['db'] ->getOne($sql);
	}
	return $result;
}

/**
 *  miracle获取用户订单详细数据
 *
 * @access  public
 * @param   int         $order_id        订单号
 */
function get_user_ordersinfo($order_id)
{
	global $_CFG, $_LANG;
	
    /* 取得订单列表 */
    $arr    = array();

    $sql = "SELECT *, " .
           "(goods_amount + shipping_fee + insure_fee + pay_fee + pack_fee + card_fee + tax - discount - goods_discount_fee) AS total_fee ".
           " FROM " .$GLOBALS['ecs']->table('order_info') .
           " WHERE order_id=$order_id";
    $row = $GLOBALS['db']->getRow($sql);

	if ($row['order_status'] == OS_UNCONFIRMED)
	{
		$row['handler'] = "<a href=\"user.php?act=cancel_order&order_id=" .$row['order_id']. "\" onclick=\"if (!confirm('".$GLOBALS['_LANG']['confirm_cancel']."')) return false;\">".$GLOBALS['_LANG']['cancel']."</a>";
	}
	else if ($row['order_status'] == OS_SPLITED)
	{
		/* 对配送状态的处理 */
		if ($row['shipping_status'] == SS_SHIPPED)
		{
			@$row['handler'] = "<a href=\"user.php?act=affirm_received&order_id=" .$row['order_id']. "\" onclick=\"if (!confirm('".$GLOBALS['_LANG']['confirm_received']."')) return false;\">".$GLOBALS['_LANG']['received']."</a>";
		}
		elseif ($row['shipping_status'] == SS_RECEIVED)
		{
			@$row['handler'] = '<span style="color:red">'.$GLOBALS['_LANG']['ss_received'] .'</span>';
		}
		else
		{
			if ($row['pay_status'] == PS_UNPAYED)
			{
				@$row['handler'] = "<a href=\"user.php?act=order_detail&order_id=" .$row['order_id']. '">' .$GLOBALS['_LANG']['pay_money']. '</a>';
			}
			else
			{
				@$row['handler'] = "<a href=\"user.php?act=order_detail&order_id=" .$row['order_id']. '">' .$GLOBALS['_LANG']['view_order']. '</a>';
			}

		}
	}
	else
	{
		$row['handler'] = '<span style="color:#565656">'.$GLOBALS['_LANG']['os'][$row['order_status']] .'</span>';
	}

	$row['shipping_status'] = ($row['shipping_status'] == SS_SHIPPED_ING) ? SS_PREPARING : $row['shipping_status'];
	$row['order_status_id'] = $row['order_status'];
	$row['order_status'] = $GLOBALS['_LANG']['os'][$row['order_status']] . ',' . $GLOBALS['_LANG']['ps'][$row['pay_status']] . ',' . $GLOBALS['_LANG']['ss'][$row['shipping_status']];

	$row['order_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
	$row['total_fee'] = price_format($row['total_fee'], false);
	$row['money_paid'] = price_format($row['money_paid'], false);
	$row['ajust_refund'] = price_format($row['ajust_refund'], false);
	$row['shipping_fee'] = price_format($row['shipping_fee'], false);
	$row['formated_discount'] = price_format($row['discount'], false);
	$row['formated_tax'] = price_format($row['tax'], false);
	$row['formated_pay_fee'] = price_format($row['pay_fee'], false);
	$row['province_name'] = get_region_name($row['province']);
	$row['city_name'] = get_region_name($row['city']);
	$row['district_name'] = get_region_name($row['district']);
	$row['goods_list'] = order_goods($order_id);
	
	include_once(ROOT_PATH . 'includes/lib_payment.php');
	include_once(ROOT_PATH . 'includes/lib_clips.php');
	
	/* 如果是未付款状态，生成支付按钮 */
    if ($row['pay_status'] == PS_UNPAYED &&
        ($row['order_status'] == OS_UNCONFIRMED ||
        $row['order_status'] == OS_CONFIRMED))
    {
        /*
         * 在线支付按钮
         */
        //支付方式信息
        $payment_info = array();
        $payment_info = payment_info($row['pay_id']);

        //无效支付方式
        if ($payment_info === false)
        {
            $row['pay_online'] = '';
        }
        else
        {
            //取得支付信息，生成支付代码
            $payment = unserialize_config($payment_info['pay_config']);

            //获取需要支付的log_id
            $row['log_id']    = get_paylog_id($row['order_id'], $pay_type = PAY_ORDER);
            $row['user_name'] = $_SESSION['user_name'];
            $row['pay_desc']  = $payment_info['pay_desc'];
            $row['pay_code'] = $payment_info['pay_code'];

            /* 调用相应的支付方式文件 */
            include_once(ROOT_PATH . 'includes/modules/payment/' . $payment_info['pay_code'] . '.php');

            /* 取得在线支付方式的支付按钮 */
            $pay_obj    = new $payment_info['pay_code'];
            $row['pay_online'] = $pay_obj->get_code($row, $payment);
        }
    }
    else
    {
        $row['pay_online'] = '';
    }
	
	/* 取得订单操作记录 */
    $act_list = array();
    $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('order_action') . " WHERE order_id = '$order_id' ORDER BY log_time DESC,action_id DESC";
    $result = $GLOBALS['db']->query($sql);
    while ($rowt = $GLOBALS['db']->fetchRow($result))
    {
        $rowt['order_status']    = $_LANG['os'][$rowt['order_status']];
        $rowt['pay_status']      = $_LANG['ps'][$rowt['pay_status']];
        $rowt['shipping_status'] = $_LANG['ss'][$rowt['shipping_status']];
        $rowt['action_time']     = local_date($_CFG['time_format'], $rowt['log_time']);
        $act_list[] = $rowt;
    }
	
    $row['order_action'] = $act_list;
    return $row;
}

/**
 * 退回余额、积分、红包（取消、无效、退货时），把订单使用余额、积分、红包设为0
 * @param   array   $order  订单信息
 */
function return_user_surplus_integral_bonus($order)
{
    /* 处理余额、积分、红包 */
    if ($order['user_id'] > 0 && $order['surplus'] > 0)
    {
        $surplus = $order['money_paid'] < 0 ? $order['surplus'] + $order['money_paid'] : $order['surplus'];
        log_account_change($order['user_id'], $surplus, 0, 0, 0, sprintf($GLOBALS['_LANG']['return_order_surplus'], $order['order_sn']));
        $GLOBALS['db']->query("UPDATE ". $GLOBALS['ecs']->table('order_info') . " SET `order_amount` = '0' WHERE `order_id` =". $order['order_id']);
    }

    if ($order['user_id'] > 0 && $order['integral'] > 0)
    {
        log_account_change($order['user_id'], 0, 0, 0, $order['integral'], sprintf($GLOBALS['_LANG']['return_order_integral'], $order['order_sn']));
    }

    if ($order['bonus_id'] > 0)
    {
        unuse_bonus($order['bonus_id']);
    }

    /* 修改订单 */
    $arr = array(
        'bonus_id'  => 0,
        'bonus'     => 0,
        'integral'  => 0,
        'integral_money'    => 0,
        'surplus'   => 0
    );
    update_order($order['order_id'], $arr);
}

/**

 * miracle取得订单商品

 * @param   array     $order  订单数组

 * @return array

 */

function get_order_goods($order)

{

    $goods_list = array();

    $goods_attr = array();

    $sql = "SELECT o.*, g.suppliers_id AS suppliers_id,IF(o.product_id > 0, p.product_number, g.goods_number) AS storage, o.goods_attr, IFNULL(b.brand_name, '') AS brand_name, p.product_sn " .

            "FROM " . $GLOBALS['ecs']->table('order_goods') . " AS o ".

            "LEFT JOIN " . $GLOBALS['ecs']->table('products') . " AS p ON o.product_id = p.product_id " .

            "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON o.goods_id = g.goods_id " .

            "LEFT JOIN " . $GLOBALS['ecs']->table('brand') . " AS b ON g.brand_id = b.brand_id " .

            "WHERE o.order_id = '$order[order_id]' ";

    $res = $GLOBALS['db']->query($sql);

    while ($row = $GLOBALS['db']->fetchRow($res))

    {

        // 虚拟商品支持

        if ($row['is_real'] == 0)

        {

            /* 取得语言项 */

            $filename = ROOT_PATH . 'plugins/' . $row['extension_code'] . '/languages/common_' . $GLOBALS['_CFG']['lang'] . '.php';

            if (file_exists($filename))

            {

                include_once($filename);

                if (!empty($GLOBALS['_LANG'][$row['extension_code'].'_link']))

                {

                    $row['goods_name'] = $row['goods_name'] . sprintf($GLOBALS['_LANG'][$row['extension_code'].'_link'], $row['goods_id'], $order['order_sn']);

                }

            }

        }



        $row['formated_subtotal']       = price_format($row['goods_price'] * $row['goods_number']);

        $row['formated_goods_price']    = price_format($row['goods_price']);



        $goods_attr[] = explode(' ', trim($row['goods_attr'])); //将商品属性拆分为一个数组



        if ($row['extension_code'] == 'package_buy')

        {

            $row['storage'] = '';

            $row['brand_name'] = '';

            $row['package_goods_list'] = get_package_goods_list($row['goods_id']);

        }



        //处理货品id

        $row['product_id'] = empty($row['product_id']) ? 0 : $row['product_id'];



        $goods_list[] = $row;

    }



    $attr = array();

    $arr  = array();

    foreach ($goods_attr AS $index => $array_val)

    {

        foreach ($array_val AS $value)

        {

            $arr = explode(':', $value);//以 : 号将属性拆开

            $attr[$index][] =  @array('name' => $arr[0], 'value' => $arr[1]);

        }

    }



    return array('goods_list' => $goods_list, 'attr' => $attr);

}

/**

 * miracle返回某个订单可执行的操作列表，包括权限判断

 * @param   array   $order      订单信息 order_status, shipping_status, pay_status

 * @param   bool    $is_cod     支付方式是否货到付款

 * @return  array   可执行的操作  confirm, pay, unpay, prepare, ship, unship, receive, cancel, invalid, return, drop

 * 格式 array('confirm' => true, 'pay' => true)

 */

function operable_list($order)

{

    /* 取得订单状态、发货状态、付款状态 */

    $os = $order['order_status'];

    $ss = $order['shipping_status'];

    $ps = $order['pay_status'];

    /* 取得订单操作权限 */

    $actions = $_SESSION['action_list'];

    if ($actions == 'all')

    {

        $priv_list  = array('os' => true, 'ss' => true, 'ps' => true, 'edit' => true);

    }

    else

    {

        $actions    = ',' . $actions . ',';

        $priv_list  = array(

            'os'    => strpos($actions, ',order_os_edit,') !== false,

            'ss'    => strpos($actions, ',order_ss_edit,') !== false,

            'ps'    => strpos($actions, ',order_ps_edit,') !== false,

            'edit'  => strpos($actions, ',order_edit,') !== false

        );

    }



    /* 取得订单支付方式是否货到付款 */

    $payment = payment_info($order['pay_id']);

    $is_cod  = $payment['is_cod'] == 1;



    /* 根据状态返回可执行操作 */

    $list = array();

    if (OS_UNCONFIRMED == $os)

    {

        /* 状态：未确认 => 未付款、未发货 */

        if ($priv_list['os'])

        {

            $list['confirm']    = true; // 确认

            $list['invalid']    = true; // 无效

            $list['cancel']     = true; // 取消

            if ($is_cod)

            {

                /* 货到付款 */

                if ($priv_list['ss'])

                {

                    $list['prepare'] = true; // 配货

                    $list['split'] = true; // 分单

                }

            }

            else

            {

                /* 不是货到付款 */

                if ($priv_list['ps'])

                {

                    $list['pay'] = true;  // 付款

                }

            }

        }

    }

    elseif (OS_CONFIRMED == $os || OS_SPLITED == $os || OS_SPLITING_PART == $os)

    {

        /* 状态：已确认 */

        if (PS_UNPAYED == $ps)

        {

            /* 状态：已确认、未付款 */

            if (SS_UNSHIPPED == $ss || SS_PREPARING == $ss)

            {

                /* 状态：已确认、未付款、未发货（或配货中） */

                if ($priv_list['os'])

                {

                    $list['cancel'] = true; // 取消

                    $list['invalid'] = true; // 无效

                }

                if ($is_cod)

                {

                    /* 货到付款 */

                    if ($priv_list['ss'])

                    {

                        if (SS_UNSHIPPED == $ss)

                        {

                            $list['prepare'] = true; // 配货

                        }

                        $list['split'] = true; // 分单

                    }

                }

                else

                {

                    /* 不是货到付款 */

                    if ($priv_list['ps'])

                    {

                        $list['pay'] = true; // 付款

                    }

                }

            }

            /* 状态：已确认、未付款、发货中 */

            elseif (SS_SHIPPED_ING == $ss || SS_SHIPPED_PART == $ss)

            {

                // 部分分单

                if (OS_SPLITING_PART == $os)

                {

                    $list['split'] = true; // 分单

                }

                $list['to_delivery'] = true; // 去发货

            }

            else

            {

                /* 状态：已确认、未付款、已发货或已收货 => 货到付款 */

                if ($priv_list['ps'])

                {

                    $list['pay'] = true; // 付款

                }

                if ($priv_list['ss'])

                {

                    if (SS_SHIPPED == $ss)

                    {

                        $list['receive'] = true; // 收货确认

                    }

                    $list['unship'] = true; // 设为未发货

                    if ($priv_list['os'])

                    {

                        $list['return'] = true; // 退货

                    }

                }

            }

        }

        else

        {

            /* 状态：已确认、已付款和付款中 */

            if (SS_UNSHIPPED == $ss || SS_PREPARING == $ss)

            {

                /* 状态：已确认、已付款和付款中、未发货（配货中） => 不是货到付款 */

                if ($priv_list['ss'])

                {

                    if (SS_UNSHIPPED == $ss)

                    {

                        $list['prepare'] = true; // 配货

                    }

                    $list['split'] = true; // 分单

                }

                if ($priv_list['ps'])

                {

                    $list['unpay'] = true; // 设为未付款

                    if ($priv_list['os'])

                    {

                        $list['cancel'] = true; // 取消

                    }

                }

            }

            /* 状态：已确认、未付款、发货中 */

            elseif (SS_SHIPPED_ING == $ss || SS_SHIPPED_PART == $ss)

            {

                // 部分分单

                if (OS_SPLITING_PART == $os)

                {

                    $list['split'] = true; // 分单

                }

                $list['to_delivery'] = true; // 去发货

            }

            else

            {

                /* 状态：已确认、已付款和付款中、已发货或已收货 */

                if ($priv_list['ss'])

                {

                    if (SS_SHIPPED == $ss)

                    {

                        $list['receive'] = true; // 收货确认

                    }

                    if (!$is_cod)

                    {

                        $list['unship'] = true; // 设为未发货

                    }

                }

                if ($priv_list['ps'] && $is_cod)

                {

                    $list['unpay']  = true; // 设为未付款

                }

                if ($priv_list['os'] && $priv_list['ss'] && $priv_list['ps'])

                {

                    $list['return'] = true; // 退货（包括退款）

                }

            }

        }

    }

    elseif (OS_CANCELED == $os)

    {

        /* 状态：取消 */

        if ($priv_list['os'])

        {

            $list['confirm'] = true;

        }

        if ($priv_list['edit'])

        {

            $list['remove'] = true;

        }

    }

    elseif (OS_INVALID == $os)

    {

        /* 状态：无效 */

        if ($priv_list['os'])

        {

            $list['confirm'] = true;

        }

        if ($priv_list['edit'])

        {

            $list['remove'] = true;

        }

    }

    elseif (OS_RETURNED == $os)

    {

        /* 状态：退货 */

        if ($priv_list['os'])

        {

            $list['confirm'] = true;

        }

    }



    /* 修正发货操作 */

    if (!empty($list['split']))

    {

        /* 如果是团购活动且未处理成功，不能发货 */

        if ($order['extension_code'] == 'group_buy')

        {

            include_once(ROOT_PATH . 'includes/lib_goods.php');

            $group_buy = group_buy_info(intval($order['extension_id']));

            if ($group_buy['status'] != GBS_SUCCEED)

            {

                unset($list['split']);

                unset($list['to_delivery']);

            }

        }



        /* 如果部分发货 不允许 取消 订单 */

        if (order_deliveryed($order['order_id']))

        {

            $list['return'] = true; // 退货（包括退款）

            unset($list['cancel']); // 取消

        }

    }



    /* 售后 */

    $list['after_service'] = true;



    return $list;

}

/**

 * miracle订单中的商品是否已经全部发货

 * @param   int     $order_id  订单 id

 * @return  int     1，全部发货；0，未全部发货

 */

function get_order_finish($order_id)

{

    $return_res = 0;



    if (empty($order_id))

    {

        return $return_res;

    }



    $sql = 'SELECT COUNT(rec_id)

            FROM ' . $GLOBALS['ecs']->table('order_goods') . '

            WHERE order_id = \'' . $order_id . '\'

            AND goods_number > send_number';



    $sum = $GLOBALS['db']->getOne($sql);

    if (empty($sum))

    {

        $return_res = 1;

    }



    return $return_res;

}


/**

 * miracle取得发货单信息

 * @param   int     $delivery_order   发货单id（如果delivery_order > 0 就按id查，否则按sn查）

 * @param   string  $delivery_sn      发货单号

 * @return  array   发货单信息（金额都有相应格式化的字段，前缀是formated_）

 */

function delivery_order_info($delivery_id, $delivery_sn = '')

{

    $return_order = array();

    if (empty($delivery_id) || !is_numeric($delivery_id))

    {

        return $return_order;

    }



    $where = '';

    $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('delivery_order');

    if ($delivery_id > 0)

    {

        $sql .= " WHERE delivery_id = '$delivery_id'";

    }

    else

    {

        $sql .= " WHERE delivery_sn = '$delivery_sn'";

    }



    $sql .= $where;

    $sql .= " LIMIT 0, 1";

    $delivery = $GLOBALS['db']->getRow($sql);

    if ($delivery)

    {

        /* 格式化金额字段 */

        $delivery['formated_insure_fee']     = price_format($delivery['insure_fee'], false);

        $delivery['formated_shipping_fee']   = price_format($delivery['shipping_fee'], false);



        /* 格式化时间字段 */

        $delivery['formated_add_time']       = local_date($GLOBALS['_CFG']['time_format'], $delivery['add_time']);

        $delivery['formated_update_time']    = local_date($GLOBALS['_CFG']['time_format'], $delivery['update_time']);



        $return_order = $delivery;

    }



    return $return_order;

}

/**

 * miracle判断订单的发货单是否全部发货

 * @param   int     $order_id  订单 id

 * @return  int     1，全部发货；0，未全部发货；-1，部分发货；-2，完全没发货；

 */

function get_all_delivery_finish($order_id)

{

    $return_res = 0;



    if (empty($order_id))

    {

        return $return_res;

    }



    /* 未全部分单 */

    if (!get_order_finish($order_id))

    {

        return $return_res;

    }

    /* 已全部分单 */

    else

    {

        // 是否全部发货

        $sql = "SELECT COUNT(delivery_id)

                FROM " . $GLOBALS['ecs']->table('delivery_order') . "

                WHERE order_id = '$order_id'

                AND status = 2 ";

        $sum = $GLOBALS['db']->getOne($sql);

        // 全部发货

        if (empty($sum))

        {

            $return_res = 1;

        }

        // 未全部发货

        else

        {

            /* 订单全部发货中时：当前发货单总数 */

            $sql = "SELECT COUNT(delivery_id)

            FROM " . $GLOBALS['ecs']->table('delivery_order') . "

            WHERE order_id = '$order_id'

            AND status <> 1 ";

            $_sum = $GLOBALS['db']->getOne($sql);

            if ($_sum == $sum)

            {

                $return_res = -2; // 完全没发货

            }

            else

            {

                $return_res = -1; // 部分发货

            }

        }

    }



    return $return_res;

}
//自定义商品添加购物车
function customer_cart_add($goods_name,$goods_price,$tax_type,$qty,$is_shipping)
{
    $user_id = $_SESSION['user_id'];
    $session_id = SESS_ID;
    $market_price = $goods_price * 1.2;
    $sql = ' INSERT INTO '.$GLOBALS['ecs']->table('cart').'( user_id, session_id, goods_id, goods_sn, product_id, goods_name, market_price, goods_price, goods_number, is_real, parent_id, rec_type, is_gift, is_shipping, can_handsel ) VALUES( '.$user_id.' , "'.$session_id.'" , 0 , "自定义", 0, "'.$goods_name.'", '.$market_price.', '.$goods_price.', '.$qty.', 1, 0, 0, 0, '.$is_shipping.', 0 )';
    $GLOBALS['db']->query($sql);
}
?>